<?php
declare (strict_types=1);

namespace app\controller\api;

use app\model\FxUsers;
use app\model\Users;
use app\util\Tools;
use think\Exception;
use think\facade\App;
use think\Response;
/**
 * 用户端相关
 */
class User extends Base {

    public function index(): Response {
        $version = config('apiadmin.APP_VERSION');
        if (!$version) {
            throw new Exception('请先执行安装脚本，完成项目初始化！');
        } else {
            return $this->buildSuccess([
                'Product'    => config('apiadmin.APP_NAME'),
                'ApiVersion' => $version,
                'TpVersion'  => App::version(),
                'Company'    => config('apiadmin.COMPANY_NAME'),
                'ToYou'      => "（终于等到你2244！）"
            ]
        );
        }
    }

    public function user_login():Response
    {
        $param = $this->request->param();
        $username = $param['username'];//手机
        $pwd = $param['pwd'];//密码
        if(empty($username) || empty($pwd)){
            return $this->buildFailed(400, '参数不正确');
        }
        $map['user_phone'] = $username;//用户手机号
       $password = Tools::userMd5($pwd);
        $map['password'] = $password;//密码
        $map['user_status'] = 1;
        $userFind = FxUsers::where($map)->find()->toArray();
        if(empty($userFind)){
            return $this->buildFailed(400, '密码不正确');
        }else{
            unset($userFind['password']);
            return $this->buildSuccess($userFind);
        }
    }
}
